$(window).load(function(){
//----------------------------------------------------------      
  $.post('weather.php', function(data) {
    $('#weather').html(data);
  });
  load_rasp();
//----------------------------------------------------------      
  preload_images(['/img/photo/ds1_small.png',
                  '/img/photo/ds2_small.png',
                  '/img/photo/ds3_small.png',
                  '/img/photo/ds4_small.png',
                  '/img/photo/ds5_small.png',
                  '/img/photo/ds6_small.png',
                  '/img/photo/ds1.jpg',
                  '/img/photo/ds2.jpg',
                  '/img/photo/ds3.jpg',
                  '/img/photo/ds4.jpg',
                  '/img/photo/ds5.jpg',
                  '/img/photo/ds6.jpg',
                  ]);
//----------------------------------------------------------    
  $("#ds1").css('background','url(/img/photo/ds1_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '180deg'});
  $("#ds2").css('background','url(/img/photo/ds2_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '-180deg'});
  $("#ds3").css('background','url(/img/photo/ds3_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '180deg'});
  $("#ds4").css('background','url(/img/photo/ds4_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '180deg'});
  $("#ds5").css('background','url(/img/photo/ds5_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '-180deg'});
  $("#ds6").css('background','url(/img/photo/ds6_small.png)').css('opacity','0').transform({ scale: [0.1,0.1], rotate: '180deg'});
  
  $("#ds1").animate({ scale: [1,1], rotate: '7deg', opacity: 1 },{ duration: 800 });
  $("#ds2").delay(300).animate({ scale: [1,1], rotate: '-3deg', opacity: 1 },{ duration: 800 });
  $("#ds3").delay(600).animate({ scale: [1,1], rotate: '-9deg', opacity: 1 },{ duration: 800 });
  $("#ds4").delay(900).animate({ scale: [1,1], rotate: '-9deg', opacity: 1 },{ duration: 800 });
  $("#ds5").delay(1200).animate({ scale: [1,1], rotate: '-4deg', opacity: 1 },{ duration: 800 });
  $("#ds6").delay(1500).animate({ scale: [1,1], rotate: '7deg', opacity: 1 },{ duration: 800 });
//----------------------------------------------------------      
  $("#ds1").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds2");
    decZindex("#ds3");
  });
  
  $("#ds2").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds1");
    decZindex("#ds3");
  });
  
  $("#ds3").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds1");
    decZindex("#ds2");
  });

  $("#ds4").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds5");
    decZindex("#ds6");
  });
  
  $("#ds5").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds4");
    decZindex("#ds6");
  });
  
  $("#ds6").mouseenter(function() {
    $(this).css('z-index',3).animate({ scale: 1.1 },{ duration: 300});
    decZindex("#ds4");
    decZindex("#ds5");
  });

  $(".service_small_img").mouseleave(function() { $(this).animate({ scale: 1 },{ duration: 300}); });

//----------------------------------------------------------    
  var current_preview='undefined';
  $("#ds1").click( function() { show_preview(this,'/img/photo/ds1.jpg','7deg'); });
  $("#ds2").click( function() { show_preview(this,'/img/photo/ds2.jpg','-3deg'); });
  $("#ds3").click( function() { show_preview(this,'/img/photo/ds3.jpg','-9deg'); });
  $("#ds4").click( function() { show_preview(this,'/img/photo/ds4.jpg','-9deg'); });
  $("#ds5").click( function() { show_preview(this,'/img/photo/ds5.jpg','-4deg'); });
  $("#ds6").click( function() { show_preview(this,'/img/photo/ds6.jpg','7deg'); });
  
//----------------------------------------------------------    
  $('.preview_close').click(function(e) {
    e.preventDefault();
    $('#mask').hide();
    $('.preview_window').hide();
    if (current_preview!='undefined') $(current_preview).animate({opacity:1},200);
  });
//----------------------------------------------------------  
  function show_preview(id,imgfile,rot) {
    var winW=660;
    var winH=488;
    current_preview=id;
    $('#mask').width($(window).width()).height($(document).height()).fadeTo(200,0.7);
    $('.preview_window').width(winW)
                        .height(winH)
                        .css('background','url('+imgfile+')')
                        .transform({scale:[1.1/(winW/$(id).width()),1.1/(winH/$(id).height())], rotate: rot})
                        .css({'left':$(id).offset().left-(winW-$(id).width())/2, 'top':$(id).offset().top-(winH-$(id).height())/2})
                        .fadeTo(1,1);
    $(id).animate({opacity:0},200);
    $('.preview_window').animate({scale : [1,1],
                                  rotate: '0deg',
                                  left  : ($(window).width()-winW)/2,
                                  top   : ($(window).height()-winH)/2
    },500);
  }
//----------------------------------------------------------
  function decZindex(el) {
    if ($(el).css('z-index')>0) { $(el).css('z-index',$(el).css('z-index')-1); }
  }  

//----------------------------------------------------------
  function preload_images(images) {
    if (typeof document.body == "undefined") return;
    try {
      var div=document.createElement("div");
      var s=div.style;
      s.position = "absolute";
      s.top=s.left=0;
      s.visibility="hidden";
      document.body.appendChild(div);
      div.innerHTML="<img src=\""+images.join("\" /><img src=\"") + "\" />";
      var lastImg=div.lastChild;
      lastImg.onload = function() { document.body.removeChild(document.body.lastChild); };
    }
    catch(e) { }
  }
  
});